package com.chhlz.module.base.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.apache.catalina.tribes.util.Arrays;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;

/***
 * 点单实体
 * @author asphaltt
 *
 */
@Entity
@Table(name="bill")
@DynamicInsert(true)
@DynamicUpdate(true)
public class Bill implements java.io.Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -4474422680762545657L;
	private int billId;
	private String billNumber;
	private String createBillTime;
	private String finishBillTime;
	private double consumption;
	private ConsumptionPattern pattern;
	private String description;
	private Set<Dish> dishes = new HashSet<Dish>();
	private Set<DiningTable> tables = new HashSet<DiningTable>();
	
	@Id
	@Column(name = "bill_id", nullable = false, length = 11)
	@GeneratedValue(generator = "generator") 
	@GenericGenerator(name = "generator", strategy = "increment") 
	public int getBillId() {
		return billId;
	}
	public void setBillId(int billId) {
		this.billId = billId;
	}
	
	@Column(name = "bill_number", nullable = false, length = 50)
	public String getBillNumber() {
		return billNumber;
	}
	public void setBillNumber(String billNumber) {
		this.billNumber = billNumber;
	}
	@Column(name = "create_bill_time", nullable = false)
	public String getCreateBillTime() {
		return createBillTime;
	}
	public void setCreateBillTime(String createBillTime) {
		this.createBillTime = createBillTime;
	}
	@Column(name = "finish_bill_time")
	public String getFinishBillTime() {
		return finishBillTime;
	}
	public void setFinishBillTime(String finishBillTime) {
		this.finishBillTime = finishBillTime;
	}
	@Column(name = "consumption", nullable = false)
	public double getConsumption() {
		return consumption;
	}
	public void setConsumption(double consumption) {
		this.consumption = consumption;
	}
	@ManyToOne
	@JoinColumn(name = "consumption_pattern_id")
	public ConsumptionPattern getPattern() {
		return pattern;
	}
	public void setPattern(ConsumptionPattern pattern) {
		this.pattern = pattern;
	}
	@Column(name = "description", length = 255)
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	@OneToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER)
	@JoinTable(name="bill_dish",
    	joinColumns={@JoinColumn(name="bill_id")},
    	inverseJoinColumns={@JoinColumn(name="dish_id")})
	public Set<Dish> getDishes() {
		return dishes;
	}
	public void setDishes(Set<Dish> dishes) {
		this.dishes = dishes;
	}
	
	@OneToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER)
	@JoinTable(name="bill_table",
    	joinColumns={@JoinColumn(name="bill_id")},
    	inverseJoinColumns={@JoinColumn(name="table_id")})
	public Set<DiningTable> getTables() {
		return tables;
	}
	public void setTables(Set<DiningTable> tables) {
		this.tables = tables;
	}
	@Override
	public String toString() {
		return "Bill [billId=" + billId + ", billNumber=" + billNumber
				+ ", createBillTime=" + createBillTime + ", finishBillTime="
				+ finishBillTime + ", consumption=" + consumption
				+ ", pattern=" + pattern + ", description=" + description
				+ ", dishes=" + Arrays.toString(dishes.toArray()) 
				+ ", tables=" + Arrays.toString(tables.toArray()) + "]";
	}

}
